import { Component, OnInit } from '@angular/core';
import { HttpService } from '@core/services/http.service';
import {ActivatedRoute} from '@angular/router';
import swal, {SweetAlertType} from 'sweetalert2';

@Component({
  selector: 'app-student-drill',
  templateUrl: './student-drill.component.html',
  styleUrls: ['./student-drill.component.less']
})
export class StudentDrillComponent implements OnInit {

    data = [];  // 演练数据
    loading = false;
    total = 0; // 总数据条数
    Pi = 1;  // 页码
    Ps = 10;  // 每页数量
    key = ''; // 检索关键字
    id; // 演练id
    showModal = false;
    modalLoading = false;
    score; // 综合评分
    evaluate; // 教师评价
    currentUid;
    constructor(public http: HttpService, private ActiveRoute: ActivatedRoute) { }

    ngOnInit() {
        this.ActiveRoute.params.subscribe(res => {
            if (res.id) {
                this.id = res.id;
                this.getData(this.id, this.Pi, this.Ps);
            }
        });
    }

    refreshData() {

    }

    getData(id, pi, ps) {
        this.http.getExercisesInfoBySimId({ sim_id: id, pi: pi, ps: ps }).subscribe(res => {
            if (res.list && res.list.length) {
                this.data = res['list'];
                this.total = res['total'];
            }
        });
    }


    show(u_id) {
        this.currentUid = u_id;
        this.showModal = true;
    }

    // 点评保存
    save() {
        this.http.updateScore({u_id: this.currentUid, sim_id: this.id, techScore: this.score, Comment: this.evaluate}).subscribe(res => {
            swal(`${res.msg}`, '' , 'success');
            this.showModal = false
        });
    }
    goBack(){
        history.back()
    }


}
